<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery-3.6.0.js"></script>
</head>
<style>
    .box {
        width: 300px;
        height: 300px;
        background-color: pink;
        display: none;
    }
</style>

<body>
    <form name="animationForm">
        <p>速度</p>
        <input type="radio" name="speed" value="slow">slow
        <input type="radio" name="speed" value="normal">normal
        <input type="radio" name="speed" value="fast">fast
        <input type="number" class="num-speed" name="speed">ms
        <p>效果</p>
        <input type="radio" name="easing" value="swing">swing
        <input type="radio" name="easing" value="linear">linear
        <br>
    </form>
    <button data-type="show">显示</button>
    <button data-type="hide">隐藏</button>
    <button data-type="toggle">切换</button>

    <div class="box"></div>
    <script>
        $('button').click(function () {
            //获取表单内所有的元素
            let elements = document.forms.animationForm.elements;
            //获取元素中name为speed中的值
            let speed = elements.speed.value;
            //获取元素中name为easing中的值
            let easing = elements.easing.value;
            //获取到input类型为number中的value值 将他转换为number类型 
            let numspeed = +document.querySelector('.num-speed').value;
            //判断如果元素中name为speed中的值如果为空即为用户没有选择单选框，将numspeed值带到参数中
            if (speed == '') {
                if (this.dataset.type === 'show') {
                    $('.box').slideDown(numspeed, easing);
                } else if (this.dataset.type === 'hide') {
                    $('.box').slideUp(numspeed, easing);
                } else {
                    $('.box').slideToggle(numspeed, easing);
                }
            } else {
                if (this.dataset.type === 'show') {
                    $('.box').slideDown(speed, easing);
                } else if (this.dataset.type === 'hide') {
                    $('.box').slideUp(speed, easing);
                } else {
                    $('.box').slideToggle(speed, easing);
                }
            }

        })
    </script>
</body>

</html>